package com.sailfish.springbootdemo.controller.db1;


import com.sailfish.springbootdemo.pojo.Result;
import com.sailfish.springbootdemo.service.db1.FileGroupService;
import com.sailfish.springbootdemo.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/fileGroup")
@CrossOrigin
public class FileGroupController {

    @Autowired
    private FileGroupService fileGroupService;

    @PostMapping("/getFileGroupById")
    public Result getFileGroupById(Integer fileGroupId) {
        try {
            if (fileGroupId == null || "".equals(fileGroupId.toString())) {
                return ResultUtil.error(500, "缺少参数status", "Miss Param status", null);
            }
            return ResultUtil.success(fileGroupService.getFileGroupById(fileGroupId));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @PostMapping("/getAllFileGroup")
    public Result getAllFileGroup() {
        try {
            return ResultUtil.success(fileGroupService.getAllFileGroup());
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }
}
